package com.apples.hexviewer2.models;

import android.util.Size;

import com.apples.hexviewer2.utils.SysHelper;

import java.util.List;

/**
 * ******************************************************************************
 * <p><b>Project HexViewer</b><br/>
 * Used with the adapters.
 * </p>
 *
 * @author Keidan
 * <p>
 * License: GPLv3
 * </p>
 * ******************************************************************************
 */
public class LineEntry {
    private final byte[] mRaw;
    public List<Size> mHighHex;
    public List<Size> mHighText;
    public int highLineNum = -1;

    public String getHex() {
        return lbthex(mRaw);
    }

    public String getAscii() {
        return lbttext(mRaw);
    }

    public LineEntry(final byte[] raw) {
        mRaw = raw;
    }

    public static String lbthex(byte[] raw) {
        StringBuilder hexString = new StringBuilder();
        for (byte b : raw) {
            hexString.append(SysHelper.formatHex((char) b, true));
            hexString.append(" ");
        }
        return hexString.toString();
    }

    public static String lbttext(byte[] raw) {
        StringBuilder stringValue = new StringBuilder();
        for (byte b : raw) {
            char character = (b >= 0x20 && b <= 0x7e) ? (char) b : (char) 0x2e;
            stringValue.append(character);
        }
        return stringValue.toString();
    }

    /**
     * Returns the raw value.
     *
     * @return List<Byte>
     */
    public byte[] getRaw() {
        return mRaw;
    }

}
